package com.software.fanfan.web.controller;

import com.software.fanfan.dao.impl.UserDaoImpl;
import com.software.fanfan.entity.model.UserModel;
import com.software.fanfan.entity.vo.Result;
import com.software.fanfan.repository.UserRepository;
import com.software.fanfan.utils.ResultUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;


/**
 * 该类用于spring boot访问静态文件的demo
 *
 * Created by shiyanfei on 2018-01-09.
 */
@Controller
@RequestMapping("/user")
public class DemoLoginController {

    private static final Logger LOGGER =  Logger.getLogger("demo");

    @Value("${name}")
    private String name;

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private UserDaoImpl userDao;


    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public String login() {
        List<UserModel> users = userRepository.findAll();
        System.out.println(users.get(0).toString());
        LOGGER.info("********************");
        return "login";
    }

    @RequestMapping(value = "/addUser",method = RequestMethod.POST)
    private Result addUser(){
        UserModel user = new UserModel();

        user.setLoginId("test");
        user.setMoble("12345678909");
        user.setUsername("yanfei");
        user.setPassword("111111");
        user.setSalt("tttt");
        String id =  userDao.create(user);
        return ResultUtil.success(id);
    }
}
